namespace ASPNET.UserControls
{
    using ASPNET.StarterKit.IssueTracker.BusinessLogicLayer;
    using System;
    using System.Diagnostics;
    using System.Runtime.CompilerServices;
    using System.Web.UI;
    using System.Web.UI.WebControls;

    public class PickSingleUser : UserControl
    {
        private ITUserCollection _DataSource;
        private bool _DisplayDefault;
        [AccessedThroughProperty("dropUsers")]
        private DropDownList _dropUsers;
        [AccessedThroughProperty("reqVal")]
        private RequiredFieldValidator _reqVal;
        private object designerPlaceholderDeclaration;

        public PickSingleUser()
        {
            base.Init += new EventHandler(this.Page_Init);
            this._DisplayDefault = false;
        }

        public override void DataBind()
        {
            this.dropUsers.Items.Clear();
            this.dropUsers.DataSource = this._DataSource;
            this.dropUsers.DataTextField = "DisplayName";
            this.dropUsers.DataValueField = "Id";
            this.dropUsers.DataBind();
            if (this._DisplayDefault)
            {
                this.dropUsers.Items.Insert(0, new ListItem("-- Select User --", "0"));
            }
        }

        [DebuggerStepThrough]
        private void InitializeComponent()
        {
        }

        private void Page_Init(object sender, EventArgs e)
        {
            this.InitializeComponent();
        }

        public void RemoveDefault()
        {
            ListItem defaultItem = this.dropUsers.Items.FindByValue("0");
            if (defaultItem != null)
            {
                this.dropUsers.Items.Remove(defaultItem);
            }
        }

        public ITUserCollection DataSource
        {
            get
            {
                return this._DataSource;
            }
            set
            {
                this._DataSource = value;
            }
        }

        public bool DisplayDefault
        {
            get
            {
                return this._DisplayDefault;
            }
            set
            {
                this._DisplayDefault = value;
            }
        }

        protected virtual DropDownList dropUsers
        {
            get
            {
                return this._dropUsers;
            }
            [MethodImpl(MethodImplOptions.Synchronized)]
            set
            {
                if (this._dropUsers != null)
                {
                }
                this._dropUsers = value;
                if (this._dropUsers != null)
                {
                }
            }
        }

        public bool Required
        {
            get
            {
                return this.reqVal.Visible;
            }
            set
            {
                this.reqVal.Visible = value;
            }
        }

        protected virtual RequiredFieldValidator reqVal
        {
            get
            {
                return this._reqVal;
            }
            [MethodImpl(MethodImplOptions.Synchronized)]
            set
            {
                if (this._reqVal != null)
                {
                }
                this._reqVal = value;
                if (this._reqVal != null)
                {
                }
            }
        }

        public int SelectedValue
        {
            get
            {
                return int.Parse(this.dropUsers.SelectedValue);
            }
            set
            {
                this.dropUsers.SelectedValue = value.ToString();
            }
        }
    }
}

